﻿@* 数据访问层测试 - 测试启动配置 - Oracle *@
@using Util.Generators.Helpers
@model Util.Generators.Contexts.EntityContext
@{
    var service = new GenerateService( Model );
    Model.Output.FileNameNoExtension = "Startup";
    Model.Output.Extension = ".cs";
    Model.Output.RelativeRootPath = $"test/{service.GetDataTestProjectPath(Util.Data.DatabaseType.Oracle )}";
}
using Util;
using Util.Helpers;

namespace @service.GetDataTestNamespace( Util.Data.DatabaseType.Oracle ) {
    /// <summary>
    /// 启动配置
    /// </summary>
    public class Startup {
        /// <summary>
        /// 配置主机
        /// </summary>
        public void ConfigureHost( IHostBuilder hostBuilder ) {
            Util.Helpers.Environment.SetDevelopment();
            hostBuilder.ConfigureDefaults( null )
                .AsBuild()
                .AddAop()
                .AddOracleUnitOfWork<@service.GetIUnitOfWork(),@service.GetUnitOfWork()>( Config.GetConnectionString( "connection" ) )
                .AddUtil();
        }

        /// <summary>
        /// 配置服务
        /// </summary>
        public void ConfigureServices( IServiceCollection services ) {
            services.AddLogging( logBuilder => logBuilder.AddXunitOutput() );
            InitDatabase( services );
        }

        /// <summary>
        /// 初始化数据库
        /// </summary>
        private void InitDatabase( IServiceCollection services ) {
            var unitOfWork = services.BuildServiceProvider().GetService<@service.GetIUnitOfWork()>();
            unitOfWork.EnsureDeleted();
            unitOfWork.EnsureCreated();
        }
    }
}